package com.lonely.web.controller.goods;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lonely.common.core.domain.api.R;
import com.lonely.goods.domain.dto.material.MaterialSubmitDTO;
import com.lonely.goods.domain.dto.material.QueryMaterialPageDTO;
import com.lonely.goods.domain.vo.material.page.MaterialDetailVO;
import com.lonely.goods.domain.vo.material.page.MaterialPageQueryVO;
import com.lonely.goods.service.IMaterialService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author : 黄志标
 * @date: 2025/7/3 9:31
 * @description: 物料请求处理器
 */
@RestController
@RequestMapping("/goodsManager/material")
@Api(tags = "商品管理/物料")
public class MaterialController {

    @Autowired
    private IMaterialService materialService;

    /**
     * 分页查询
     *
     * @param queryDto
     * @return
     */
    @PostMapping("/page")
    @ApiOperation(value = "分页查询")
    public R<Page<MaterialPageQueryVO>> page(@RequestBody @Validated QueryMaterialPageDTO queryDto) {
        return R.data(this.materialService.page(queryDto));
    }

    /**
     * 获取指定物料id对应的物料详情
     * @param materialId
     * @return
     */
    @GetMapping("/detail/{materialId}")
    @ApiOperation(value = "获取指定物料id对应的物料详情")
    public R<MaterialDetailVO> detail(@PathVariable("materialId") Long materialId){
        return R.data(this.materialService.detail(materialId));
    }


    /**
     * 创建/编辑 物料
     *
     * @param submitDto
     * @return
     */
    @PostMapping("/submit")
    @ApiOperation(value = "创建/编辑 物料")
    @SaCheckPermission("goods:material:submit")
    public R<Boolean> submit(@RequestBody @Validated MaterialSubmitDTO submitDto) {
        this.materialService.submit(submitDto);
        return R.status(true);
    }

    /**
     * 启用物料
     *
     * @param id
     * @return
     */
    @GetMapping("/enabled/{id}")
    @ApiOperation(value = "启用物料")
    @SaCheckPermission("goods:material:enabled")
    public R<Boolean> enabled(@PathVariable("id") Long id) {
        this.materialService.enabled(id);
        return R.status(true);
    }

    /**
     * 禁用物料
     *
     * @param id
     * @return
     */
    @GetMapping("/disable/{id}")
    @ApiOperation(value = "禁用物料")
    @SaCheckPermission("goods:material:disable")
    public R<Boolean> disable(@PathVariable("id") Long id) {
        this.materialService.disable(id);
        return R.status(true);
    }


}
